package com.bilibili.juc.cf;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class Test1Demo {
    public static void main(String[] args) {
        //Thread t1  = new Thread();

        FutureTask<String> ft = new FutureTask<>(new MyThread2());
        Thread t1 = new Thread(ft, "t1");
        t1.start();
        String result = null;
        try {
           result =  ft.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(result);
    }
}


class MyThread1 implements Runnable{

    @Override
    public void run() {

    }
}


class MyThread2 implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("-----come in ---------");
        TimeUnit.SECONDS.sleep(2);
        return "hello callable";
    }
}
